import java.awt.*;
import java.awt.event.*;

public class GridBagLayoutTest {
 /**
  * GridBagLayout 을 써보자. version test
  */
 public static void main(String[] args) {
  
  GridBagFrame frame = new GridBagFrame();
  
  frame.setSize(400, 300);  //크기
  frame.setLocation(200, 200); //위치
  frame.setVisible(true);   //윈도우 창 보이기
  
  //윈도우 종료 이벤트 처리
  frame.addWindowListener(new WindowAdapter(){
   public void windowClosing (WindowEvent  e) {
    System.exit(1);
   }
  });
 }
}
@SuppressWarnings("serial")
class GridBagFrame extends Frame{
 GridBagConstraints c;
 
 public GridBagFrame(){
  super("GridBagLayout ex");
  //배치 관리자 생성 및 설정
  GridBagLayout gridBag = new GridBagLayout();
  this.setLayout(gridBag);
  
  //합쳐질 셀정보를 지정
  c = new GridBagConstraints();
  c.weightx = 1.0;
  c.weighty = 1.0;
  c.fill = GridBagConstraints.BOTH;
  
  
  // 첫번째
  List list1 = new List();
  list1.add("강아지");
  list1.add("고양이");
  layout(list1,0,0,1,2);
  
  //두번째
  Panel panel2 = new Panel();
  panel2.setLayout(new BorderLayout());
  panel2.add("North", new Button("21"));
  panel2.add("West", new Button("22"));
  panel2.add("East", new Button("23"));
  panel2.add("Center", new Button("24"));
  panel2.add("South", new Button("25"));
  layout(panel2,1,0,2,1);
  
  //세번째
  Button btn3 = new Button("3");
  layout(btn3,1,1,1,1);
  
  //네번째
  Button btn4 = new Button("4");
  layout(btn4,2,1,1,1);
 }
 //자리 정보 인자값 처리 하는 메소드 
 public void layout(Component obj, int x, int y, int width, int height){
  c.gridx = x;
  c.gridy = y;
  c.gridwidth = width;
  c.gridheight = height;
  add(obj,c);
  
 }
}